package com.easyctrl.ldy.view;
   

import com.easyctrl.ldy.activity.LoginActivity; 
import com.easyctrl.ldy.activity.R;   
import com.easyctrl.manager.UserManager;
  
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.util.AttributeSet;   
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class BackView extends RelativeLayout implements OnClickListener {
	
	private LayoutInflater mInflater;
	private View view;
	private TextView titleView;
	private Button leftButton;
	private TextView host;
	private Context mContext;    
	private UserManager userManager;  
	
	   
	public BackView(Context context, AttributeSet attrs) {
		super(context, attrs); 
		this.mContext = context;
		mInflater = LayoutInflater.from(context); 
		view = mInflater.inflate(R.layout.back_view, this); 
		view.setOnClickListener(new OnClickListener() { public void onClick(View v) {  }});
		
		titleView = (TextView) view.findViewById(R.id.title);  
		leftButton = (Button) view.findViewById(R.id.leftButton);
		userManager = UserManager.getInstance(context);
		host = (TextView) view.findViewById(R.id.host); 
		host.setText(userManager.currentHost());
		
		view.findViewById(R.id.info).setOnClickListener(this);
		
		TypedArray array = context.obtainStyledAttributes(attrs,R.styleable.backview);
		 
		String leftstr = array.getString(R.styleable.backview_leftButton);
		String title = array.getString(R.styleable.backview_title); 
		
		titleView.setText(title);
		leftButton.setText(leftstr);
		
		array.recycle();  
	}
	
	public void setHostViewString(String hoststr){
		host.setText(hoststr);
	}
	
	public void setTitle(String title){
		titleView.setText(title);
	}  

	@Override
	public void onClick(View v) {
		if(v.getId() == R.id.info) {
			Intent intent = new Intent(mContext, LoginActivity.class);
			mContext.startActivity(intent);   
		} 
	}  
}
